package com.budweiser.user.dao;

import com.budweiser.model.user.Role;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface RoleDao {
	/***
	 * 根据params查询总条数
	 * 
	 * @param params
	 * @return
	 */
	int count(Map<String, Object> params);

	/***
	 * 根据params查询Rolse对象
	 */
	List<Role> findData(Map<String, Object> params);

	/***
	 * 根据role新增
	 * 
	 * @param role
	 */
	@Options(useGeneratedKeys = true, keyProperty = "id")
	@Insert("insert into sys_role(code, name, createTime, updateTime,deleteStatus) values(#{code}, #{name}, #{createTime}, #{createTime},#{deleteStatus})")
	void inset(Role role);

	/***
	 * 根据code查询Role对象
	 * 
	 * @param code
	 * @return
	 */
	@Select("select * from sys_role where code =#{code} ")
    Role findByCode(String code);

	/***
	 * 根据code查询且查询包含ID的集合
	 * 
	 * @param code
	 * @param id
	 * @return
	 */
	@Select("select * from sys_role where code=#{code} and id !=#{id} and deleteStatus =0")
    Role findByCodeAndNoId(@Param("code") String code, @Param("id") Long id);

	/***
	 * 修改
	 * 
	 * @param role
	 */
	void update(Role role);

	/***
	 * 批量修改数据为删除状态
	 */
	public void updateDelStatus(List<Long> idList);

	@Select("select * from sys_role where id =#{id}")
    Role findById(Long id);
    /***
     * 根据Id删除
     * @param id
     */
	@Delete("delete from sys_role where id = #{id}")
	void delete(Long id);
}
